import re,numpy
import cPickle as pickle

def LoadFile(fname):
	data=[]
	line="nfiles:1	size\[M\]:0.104	read:0.011	write:0.080	unlink:0.268	iowait:0.000	rusage:0.630	mrusage:0.630	wspeed\[MB/s\]:1.299"
	number="[0-9\.]+"
	fields=re.sub(number,"",line).split()
	rfields=["%s(%s)\s*"%(k,number) for k in fields]

	to_match=re.compile("".join(rfields))
	count_matched=0
	with open(fname,"r") as f:
		for line in f.readlines():
			m=to_match.search(line)
			if m:  data.append(map(float,m.groups()))
			else: 
			    count_matched+=1
			    #print "Not matched:%d lines"%count_matched
	return numpy.array(data)

def save(obj,filename):
    try:
        os.unlink(filename)
    except:pass
    f=open(filename,"w+")
    pickle.dump(obj,f)
    f.close()

def load(filename):
    f=open(filename,"r")
    obj=pickle.load(f)
    f.close()
    return obj
